package com.atguigu.gmall.product.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseSaleAttr;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.BaseSaleAttrService;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lfy
 * @Description
 * @create 2023-08-16 10:20
 */
@RequestMapping("/admin/product")
@RestController
public class BaseSaleAttrController {


    @Autowired
    BaseSaleAttrService saleAttrService;

    @Autowired
    SpuSaleAttrService spuSaleAttrService;

    /**
     * 查询所有销售属性名
     * @return
     */
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> list = saleAttrService.list();
        return Result.ok(list);
    }


    /**
     * 查询指定SPU当时定义的所有销售属性名和值
     * @return
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable("spuId") Long spuId){

        List<SpuSaleAttr> spuSaleAttrs = spuSaleAttrService.getSpuSaleAttrList(spuId);

        return Result.ok(spuSaleAttrs);
    }
}
